
use "$path\Intermediary Data\base_CIR2_sp95", clear
merge 1:1 id using "$path\Intermediary Data\moments_alt_sp95.dta"
sum kurtosis , d
local min=2.5
local max=97.5
winsor2 kurtosis , replace  cuts(`min' `max') trim
replace kurto=. if kurto>9
sum kurtosis , d
keep if _m==3
drop _m
merge 1:1 id using "$path\Intermediary Data\moments_EG_sp95"
sum freq , d
local min=2.5
local max=97.5
winsor2 freq , replace  cuts(`min' `max') trim
sum freq , d

egen tot=sum(nobs)
keep if _m==3
drop _m
merge 1:1 id using "$path\Intermediary Data\kurto_hetero_sp95"
sum k_10 , d
local min=2.5
local max=97.5
winsor2 k_10 , replace  cuts(`min' `max') trim
sum k_10 , d
winsor2 k_5 , replace  cuts(`min' `max') trim
sum k_5, d
winsor2 k_15 , replace  cuts(`min' `max') trim
sum k_15, d
winsor2 k_20 , replace  cuts(`min' `max') trim
sum k_20, d
winsor2 k_25 , replace  cuts(`min' `max') trim
sum k_25, d

keep if _m==3
drop _m


sum CIR_2 , d
local min=1
local max=99
winsor2 CIR_2 , replace  cuts(`min' `max') trim





sum nobs, d

sum sc10, d

sum CIR_2,d


gen ratio=kurtosis/freq
sum ratio, d
local min=1
local max=99
winsor2 ratio , replace  cuts(`min' `max') trim
replace freq=. if ratio==.
replace kurt=. if ratio==.

replace ratio=kurtosis/freq

gen ratio_10=k_10/freq
gen ratio_5=k_5/freq
gen ratio_15=k_15/freq
gen ratio_20=k_20/freq
gen ratio_25=k_25/freq

drop if ratio==.
drop if CIR_2==.


sort nobs
gen sum_obs=sum(nobs)

gen year=(nobs/261)


preserve
keep if year>=6

save "$path\Intermediary Data\base_suff_stat_6Y_sp95", replace

keep id
duplicates drop id, force
save "$path\Intermediary Data\base_id_suff_stat_6Y_sp95", replace
restore


*** Create light data for merge later
clear
use "$path\Intermediary Data\base_suff_stat_6Y_sp95"
keep id lt_effect kurtosis freq ratio mean skewness sd k_20 k_10 k_15 k_25
save "$path\Intermediary Data\base_base_suff_stat_6Y_sp95_forinteractkurtfreq", replace
